package com.daiqile.okgodemo.utils;

import com.blankj.utilcode.util.EmptyUtils;

/**
 * Created by 99210 on 2017/8/6.
 */

public class EncryptUtils {

    /**
     * 所有参数按照字段名的ascii码从小到大排序后使用QueryString(即&key1=value1&key2=value2&key3=value3…)拼接而成，定义为字符串C；注:如果参数值为空，则不参与拼接
     * 对字符串C MD5加密形成字符串D
     * 字符串D拼接字符串”“,即下划线，再拼接一个常量E，形成字符串F
     * 最后对字符串F md5加密形成字符串G
     * @param paramsMap 参数map
     * @param signValue 常量
     * @return
     * */
    public static String params2Asc2Sort(String str, String signValue){
        if (EmptyUtils.isEmpty(str)){
            return "";
        }
        String temp = com.blankj.utilcode.util.EncryptUtils.encryptMD5ToString(str.toString()).toLowerCase()+"_"+ signValue;
        return  com.blankj.utilcode.util.EncryptUtils.encryptMD5ToString(temp).toLowerCase();
    }

    /**截取guoan_regtime的前面5个字符拼接上一个常量A，再拼接上guoan_regtime的后5个字符，md5加密之后形成字符串B
     * http://121.41.5.82:10101/index.php?s=/13&page_id=99
     * @param constValue 常量
     * @return
     * */
    public static String createTimeStampToken(long timestamp, String constValue){
        String timeStamp = String.valueOf(timestamp);
        StringBuilder sb = new StringBuilder();
        sb.append(timeStamp.substring(0,5)).append(constValue).append(timeStamp.substring(timeStamp.length()-5,timeStamp.length()));
        return com.blankj.utilcode.util.EncryptUtils.encryptMD5ToString(sb.toString()).toLowerCase();
    }

    public static String getNowTimeStamp(){
        return String.valueOf(System.currentTimeMillis()/1000);
    }
}
